package com.cskaoyan.controller;

import com.cskaoyan.bean.vo.BaseRespVo;
import com.cskaoyan.bean.data.PageData;
import com.cskaoyan.bean.data.GoodsDetailData;
import com.cskaoyan.model.MarketGoods;
import com.cskaoyan.service.GoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Description
 * @Author zoe ling
 * @Date 2024/6/8
 */
@RestController
@RequestMapping("wx/goods")
public class WxGoodsController {
    @Autowired
    GoodsService goodsService;
    @GetMapping("count")
    public BaseRespVo count(){
        long count=goodsService.count();
        return BaseRespVo.ok(count);
    }

    @GetMapping("detail")
    public BaseRespVo detail(Integer id){
        //未登录状况下，把userId写死
        int userId=1;
       GoodsDetailData data= goodsService.detail(id,userId);
       return BaseRespVo.ok(data);
    }

    //相关商品推荐
    @GetMapping("related")
    public BaseRespVo related(@RequestParam("id")Integer id){
        MarketGoods goods=goodsService.findById(id);
        if (goods==null){
            return BaseRespVo.badArgumentValue();
        }
        Integer categoryId = goods.getCategoryId();
        int related=6;
        PageData data=goodsService.queryByCategory(categoryId,1,related);
        return BaseRespVo.ok(data);
    }
}
